#!/bin/bash
set -e
TOMCAT_USER=${TOMCAT_USER:-admin}
TOMCAT_PASS=${TOMCAT_PASS:-admin}

sed -i -r  's/<\/tomcat-users>//g'   $CATALINA_HOME/conf/tomcat-users.xml
echo '<role rolename="manager-gui"/>' >>$CATALINA_HOME/conf/tomcat-users.xml
echo '<role rolename="manager-script"/>' >>$CATALINA_HOME/conf/tomcat-users.xml
echo '<role rolename="manager-jmx"/>' >>$CATALINA_HOME/conf/tomcat-users.xml
echo '<role rolename="admin-gui"/>' >>$CATALINA_HOME/conf/tomcat-users.xml
echo '<role rolename="admin-script"/>' >>$CATALINA_HOME/conf/tomcat-users.xml
echo "<user username=\"${TOMCAT_USER}\" password=\"${TOMCAT_PASS}\" roles=\"manager-gui,manager-script,manager-jmx,admin-gui, admin-script\"/>" >>$CATALINA_HOME/conf/tomcat-users.xml
echo '</tomcat-users>' >> ${CATALINA_HOME}/conf/tomcat-users.xml 

